package feeinterface.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.ulwx.database.DataBaseSet;
import com.ulwx.database.RowMapper;
import com.ulwx.tool.DbUtils;
import feeinterface.modeldb.ChannelWap;

/**
 * 针对Wap通道的特殊附加信息
 * 
 * @author 黄杰
 * 
 */
public class ChannelWapDao {

	
	public static ChannelWap getBy(Integer channelID) throws Exception {
		String sql = "select * from  ChannelWap b  where b.ChannelID=? ";
		Map<Integer, Object> map = new HashMap<Integer, Object>();
		map.put(1, channelID);
		List<ChannelWap> list = DbUtils
				.doQueryClass(null, ChannelWap.class, sql, map);
		if(list.size()>0) return list.get(0);
		return null;
	}
		
	/**
	 * 根据通道ID获取WAP抓取步骤字符串
	 * @param channelid
	 * @return
	 * @throws Exception
	 */
	public static String getFetchByChannelID(int channelid) throws Exception {
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT WAPFetchStrs FROM ChannelWap WHERE ChannelID = ?");
		RowMapper<String> rowMapper = new RowMapper<String>() {
			@Override
			public String mapRow(DataBaseSet rs) throws Exception {
				return rs.getString("WAPFetchStrs");
			}
		};
		Map<Integer, Object> args = new HashMap<Integer, Object>();
		args.put(1, channelid);
//		DataBase db = DataBaseFactory.getDataBase();
		List<String> list = DbUtils.doQueryObject(null,sb.toString(), args, rowMapper);
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return "";
	}
}
